package com.sttk.fastMark.camera.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sttk.fastMark.camera.R;
import com.sttk.fastMark.camera.basic.ProviderMultiAdapter;
import com.sttk.fastMark.camera.bean.PhoneAlbumBean;

import org.jetbrains.annotations.NotNull;

public class AlbumChildAdapter extends ProviderMultiAdapter<PhoneAlbumBean.ClassBean> {

    private PhoneAlbumBean phoneAlbumBean;
    private boolean isEdit = false;

    public PhoneAlbumBean getPhoneAlbumBean() {
        return phoneAlbumBean;
    }

    public void setPhoneAlbumBean(PhoneAlbumBean phoneAlbumBean) {
        this.phoneAlbumBean = phoneAlbumBean;
    }

    public AlbumChildAdapter() {
        super(3);
        addItemProvider(new AlbumChildItemProvider());
        notifyDataSetChanged();
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class AlbumChildItemProvider extends BaseItemProvider<PhoneAlbumBean.ClassBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album_child;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, PhoneAlbumBean.ClassBean bean) {
            ImageView ivAlbumChildImage = baseViewHolder.getView(R.id.ivAlbumChildImage);
            Glide.with(getContext())
                    .load(bean.getPath())
                    .into(ivAlbumChildImage);

            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivAlbumChildSelector, R.drawable.xz);
            } else {
                baseViewHolder.setImageResource(R.id.ivAlbumChildSelector, R.drawable.wxz);
            }
            baseViewHolder.setGone(R.id.ivAlbumChildSelector, !isEdit);
        }
    }
}
